/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author TuanNguyen
 */
public class FilePathDAO {

    public static boolean saveFilePath(String file, String path) {
        boolean result = false;
        Connection con = ConnectDatabase.getConnection();
        try {
            PreparedStatement state = con.prepareStatement("insert into FilePath values(?,?)");
            state.setString(1, file);
            state.setString(2, path);
            int number = state.executeUpdate();
            if (number > 0) {
                result = true;
            }
            con.close();
        } catch (SQLException ex) {
//            ex.printStackTrace();
        }
        return result;
    }

    public static String getFilePath(String fileName) {
        Connection con = ConnectDatabase.getConnection();
        try {
            Statement state = con.createStatement();
            String sql = "select * from FilePath where fileName = '" + fileName + "'";
            ResultSet set = state.executeQuery(sql);
            if(set.next()){
                return set.getString(2);
            }
            con.close();
        } catch (SQLException ex) {
//            ex.printStackTrace();
        }
        return null;
    }
}
